package com.aurora_manito.xiaomi.entity;

import java.util.List;

//网站建设技术pageBean
public class PageBean1<T> {
    private int pageSize = 3;
    private int currentPageNO = 1;
    private int totalRecordCount;
    private int totalPageCount;
    private int startRowNO;
    private int startPage;          // 开始页数
    private int endPage;            // 结束页数
    protected List<T> pageList;
    private int[] pageNumbers;

    public PageBean1() {
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPageNO() {
        return currentPageNO;
    }

    public void setCurrentPageNO(int currentPageNO) {
        this.currentPageNO = currentPageNO;
    }

    public int getTotalRecordCount() {
        return totalRecordCount;
    }

    public void setTotalRecordCount(int totalRecordCount) {
        this.totalRecordCount = totalRecordCount;
        setTotalPageCountByRs();
    }

    private void setTotalPageCountByRs() {
        this.totalPageCount = totalRecordCount % pageSize == 0 ? totalRecordCount / pageSize : totalRecordCount / pageSize + 1;
        setPageNumbers(totalPageCount);//通过传递“总页数totalPageCount”，调用setNumbers(int totalPageCount)方法，以设置要展示的页码列表
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public int getStartRowNO() {
        //return startRowNO;
        return (currentPageNO - 1) * pageSize;
    }

    public void setStartRowNO(int startRowNO) {
        this.startRowNO = startRowNO;
    }

    public List<T> getPageList() {
        return pageList;
    }

    public void setPageList(List<T> pageList) {
        this.pageList = pageList;
    }

    public int[] getPageNumbers() {
        return pageNumbers;
    }

    //public void setPageNumbers(int[] pageNumbers) {
    //this.pageNumbers = pageNumbers;
    public void setPageNumbers(int totalPageCount) {
        if (totalPageCount > 0) {
            //当前数组的长度
            int[] pageNumbers = new int[totalPageCount > 10 ? 10 : totalPageCount];//页面要显示的页数集合
            int k = 0;
            //1.数组长度<10   1 2 3 4 ....   7
            //2.数组长度>=10
            //     当前页<=6  1 2 3 4    10
            //     当前页>=总页数-5......12 13 14 15
            //     其他......5  6  7 8   9 当前页(10)  10  11 12  13
            for (int i = 0; i < totalPageCount; i++) {
                //保证：区间确定时的那一刻，当前页总位于第6个位置处（除刚登录和接近尾页时的情况之外）
                if ((i >= currentPageNO - (pageNumbers.length / 2 + 1) || i >= totalPageCount - pageNumbers.length) && k < pageNumbers.length) {
                    pageNumbers[k] = i + 1;
                    k++;
                } else if (k >= pageNumbers.length) {
                    break;
                }
            }
            this.pageNumbers = pageNumbers;
        }
    }

    public int getStartPage() {

        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage=pageSize-4;
        //当前页小于5
        if(this.pageSize<5)
        {
            this.startPage=1;
        }
        //当前页大于 总也数-5
        if(this.pageSize>totalPageCount-5)
        {
            this.startPage=pageSize-9;
        }
        //总页数小于10
        if(totalPageCount<10)
        {
            this.startPage=1;
        }
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage=pageSize+5 ;
        //当前页小于5
        if(this.pageSize<5)
        {
            this.endPage=10;
        }
        //当前页大于 总也数-5
        if(this.pageSize>totalPageCount-5)
        {
            this.endPage=totalPageCount;
        }
        //总页数小于10
        if(totalPageCount<10)
        {
            this.endPage=totalPageCount;
        }
    }

    public void setPageNumbers(int[] pageNumbers) {
        this.pageNumbers = pageNumbers;
    }
}
